//
//  HRRegisterInfoViewController.m
//  SpeedDating
//
//  Created by ISU1 on 16/12/13.
//  Copyright © 2016年 isu. All rights reserved.
//

#import "RegisterInfoViewController.h"
#import "RegisterPhotoViewController.h"
#import "HSLimitText.h"
@interface RegisterInfoViewController ()<UITextFieldDelegate,HSLimitTextDelegate>


@property (nonatomic, strong) HSLimitText *nickNameTextField;  ///< textField

@property (nonatomic, strong) UITextField *birthdayTextField;



@property (nonatomic, strong) NSNumber *sex;

@property (nonatomic, strong) UIDatePicker *datePicker;

@property (nonatomic, strong) UIView *dateView;

@property (nonatomic, strong) UIButton *nextButton;

@property (nonatomic, strong) UILabel *nameLab;

@property (nonatomic, strong) UILabel *titleLab;

//星座
@property (nonatomic, strong) UILabel *constellationLab;
@property (nonatomic, strong) UIImageView *constellationImg;
@property (nonatomic, strong) NSString  *constellationStr;
@property (nonatomic, strong) NSString *stringConMon;
@property (nonatomic, strong) NSString *stringConDay;


//性别
@property (nonatomic, strong) UIButton *manButton;
@property (nonatomic, strong) UIButton *womanButton;
@property (nonatomic, strong) UIImageView *manImage;
@property (nonatomic, strong) UIImageView *womanImage;

@property (nonatomic, assign) CGFloat   titleSize;

@property (nonatomic, strong) UIButton *backButton;

@end

@implementation RegisterInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _sex = @1;
    self.view.backgroundColor = [UIColor whiteColor];
    [self setNavgationBarHidden];
    [self configureUI];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [SVProgressHUD dismiss];
}

- (void)configureUI {
    
    UIView *viewBg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 64)];
    viewBg.backgroundColor = Colorbackground;
    [self.view addSubview:viewBg];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(22, 19.5, 44, 44)];
    btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft ;//设置文字位置，现设为居左，默认的是居中
    [btn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    btn.imageEdgeInsets = UIEdgeInsetsMake(0, 5.5, 0, 0);
    [btn addTarget:self action:@selector(backActionbtn) forControlEvents:UIControlEventTouchUpInside];
    if ([_perfectType isEqualToString:@"1"]) {
        btn.hidden = YES;
    }else{
        btn.hidden = NO;
    }
    [viewBg addSubview:btn];
    
    
    if (iPhone5) {
        _titleSize = 14;
    }else if (iPhone6){
        _titleSize  = 15;
    }else{
        _titleSize = 16;
    }
    _titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 25, KScreenWidth, 34)];
    _titleLab.backgroundColor = Colorbackground;
    _titleLab.textAlignment = NSTextAlignmentCenter;
    _titleLab.text = @"完善资料";
    _titleLab.font = Font(18);
    _titleLab.textColor = [UIColor blackColor];
    
    [viewBg addSubview:_titleLab];
    
    UILabel *nickname = [[UILabel alloc] init];
    nickname.text = @"昵称";
    nickname.font = FontBold(_titleSize);
    nickname.textColor = [UIColor blackColor];
    [self.view addSubview:nickname];
    [nickname mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(20);
        make.top.equalTo(viewBg.mas_bottom).offset(0);
        make.height.mas_equalTo(45*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(55*SCREEN_WIDTH_RATIO47);

    }];
    
    
    
    
    _nickNameTextField = [[HSLimitText alloc] init];
    _nickNameTextField.type =TextInputTypeTextfield;
    _nickNameTextField.delegate = self;
    _nickNameTextField.placeholder = @"请输入昵称";
    _nickNameTextField.maxLength = 8;
    _nickNameTextField.isBecomFirstResponder = YES;
    
    
    if ([HQHttpManager userNickName].length > 0) {
        _nickNameTextField.text = [HQHttpManager userNickName];
    }else{
    
    }
    
    [self.view addSubview:_nickNameTextField];
    
    
    [_nickNameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nickname.mas_right).offset(14);
        make.right.equalTo(self.view).offset(-100);
        make.height.mas_equalTo(45*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(viewBg.mas_bottom).offset(0);
    }];
    
    
    UILabel *line1 = [[UILabel alloc] init];
    line1.backgroundColor = RGB(242, 244, 244);
    [self.view addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
        make.height.mas_equalTo(1);
        make.top.equalTo(_nickNameTextField.mas_bottom).offset(1);
    }];
    
    self.nameLab = [[UILabel alloc] init];
    self.nameLab.font = FontBold(13);
    self.nameLab.textColor = [UIColor grayColor];
//    self.nameLab.text = @"昵称长度为1~8个汉字，或1~16个字符";
    [self.view addSubview:self.nameLab];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(line1.mas_bottom).offset(2);
        make.left.mas_equalTo(30*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(25*SCREEN_WIDTH_RATIO47);
        make.right.mas_equalTo(0);
    }];
    
    UILabel *sexLabel = [[UILabel alloc] init];
    sexLabel.textColor = [UIColor blackColor];
    sexLabel.text = @"性别";
    sexLabel.font = FontBold(_titleSize);
    [self.view addSubview:sexLabel];
    [sexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(20*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(55*SCREEN_WIDTH_RATIO47);
        make.top.mas_equalTo(line1.mas_bottom).offset(2);
        make.height.mas_equalTo(45*SCREEN_WIDTH_RATIO47);
    }];

    
    _manImage = [[UIImageView alloc] init];
    _manImage.image = [UIImage imageNamed:@"boy_icon_pressed_w"];
    [self.view addSubview:_manImage];
    [_manImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(sexLabel.mas_right).offset(25*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(20*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(line1.mas_bottom).offset(11);
        make.height.mas_equalTo(25*SCREEN_WIDTH_RATIO47);
    }];
    
    _manButton = [[UIButton alloc] init];
    _manButton.selected = YES;
    [_manButton setTitle:@"男" forState:UIControlStateNormal];
    [_manButton setTitleColor:ColorI(0xcc00b8f0) forState:UIControlStateSelected];
    [_manButton addTarget:self action:@selector(clickSexButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_manButton];
    [_manButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(sexLabel.mas_right).offset(20*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(70*SCREEN_WIDTH_RATIO47);
        make.top.mas_equalTo(line1.mas_bottom).offset(2);
        make.height.mas_equalTo(45*SCREEN_WIDTH_RATIO47);
    }];
    
    _manButton.titleEdgeInsets = UIEdgeInsetsMake(0, 40, 0, 0);
    
    
    _womanImage = [[UIImageView alloc] init];
    _womanImage.image = [UIImage imageNamed:@"girl_icon_default"];
    [self.view addSubview:_womanImage];
    [_womanImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_manButton.mas_right).offset(45*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(20*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(line1.mas_bottom).offset(11);
        make.height.mas_equalTo(25*SCREEN_WIDTH_RATIO47);
    }];
    
    _womanButton = [[UIButton alloc] init];
    _womanButton.titleEdgeInsets = UIEdgeInsetsMake(0, 40, 0, 0);

    [_womanButton setTitle:@"女" forState:UIControlStateNormal];
    [_womanButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [_womanButton addTarget:self action:@selector(clickSexButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_womanButton];
    [_womanButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_manButton.mas_right).offset(40);
        make.width.mas_equalTo(70*SCREEN_WIDTH_RATIO47);
        make.top.mas_equalTo(line1.mas_bottom).offset(2);
        make.height.mas_equalTo(45*SCREEN_WIDTH_RATIO47);
    }];
    
        UILabel *line2 = [[UILabel alloc] init];
        line2.backgroundColor = TheLinColor;
        [self.view addSubview:line2];
        [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).offset(0);
            make.right.equalTo(self.view).offset(0);
            make.height.mas_equalTo(1);
            make.top.equalTo(sexLabel.mas_bottom).offset(1);
        }];
        
    
    UILabel *birthLab = [[UILabel alloc] init];
    birthLab.text = @"生日";
    birthLab.textColor = [UIColor blackColor];
    birthLab.font = FontBold(_titleSize);
    [self.view addSubview:birthLab];
    
    [birthLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(20);
        make.width.mas_equalTo(55*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(line2.mas_bottom).offset(1);
        make.height.mas_equalTo(45*SCREEN_WIDTH_RATIO47);

    }];
  
    _birthdayTextField = [[UITextField alloc] init];
    _birthdayTextField.placeholder = @"请选择出生日期";
    _birthdayTextField.userInteractionEnabled = NO;
    
    if ([HQHttpManager userBirthday].length > 0) {
        _birthdayTextField.text = [HQHttpManager userBirthday];
    }else{
        
    }
    
    [self.view addSubview:_birthdayTextField];
    [_birthdayTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(birthLab.mas_right).offset(20*SCREEN_WIDTH_RATIO47);
        make.right.equalTo(self.view).offset(0);
        make.height.mas_equalTo(45*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(line2.mas_bottom).offset(1);
    }];
    
    UIButton *birthdayButton = [[UIButton alloc] init];
    [birthdayButton addTarget:self action:@selector(clickBirthdayButton) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:birthdayButton];
    [birthdayButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(birthLab.mas_right).offset(20*SCREEN_WIDTH_RATIO47);
        make.right.equalTo(self.view).offset(0);
        make.height.mas_equalTo(45*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(line2.mas_bottom).offset(1);
    }];

    UIImageView *rightImg = [[UIImageView alloc] init];
    rightImg.image = [UIImage imageNamed:@"jiantou2"];
    [self.view addSubview:rightImg];
    [rightImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(birthdayButton.mas_right).offset(-20);
        make.width.mas_equalTo(20*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(line2.mas_bottom).offset(15);
        make.height.mas_equalTo(20*SCREEN_WIDTH_RATIO47);
    }];
    
    
 
    _constellationLab = [[UILabel alloc] init];
    _constellationLab.font = Font(_titleSize);
    _constellationLab.text = _constellationStr;
    [self.view addSubview:_constellationLab];
    [_constellationLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_birthdayTextField.mas_right).offset(-KScreenWidth/2+33*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(50*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(line2.mas_bottom).offset(1);
        make.height.mas_equalTo(45*SCREEN_WIDTH_RATIO47);
    }];
    
    _constellationImg = [[UIImageView alloc] init];
    [self.view addSubview:_constellationImg];
    [_constellationImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_constellationLab.mas_right).offset(10*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(35*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(line2.mas_bottom).offset(5);
        make.height.mas_equalTo(35*SCREEN_WIDTH_RATIO47);
    }];
    
    _constellationImg.hidden = YES;
    
    UILabel *lin3 = [[UILabel alloc] init];
    lin3.backgroundColor = TheLinColor;
    [self.view addSubview:lin3];
    [lin3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(birthLab.mas_bottom).offset(1);
        make.left.mas_equalTo(0);
        make.height.mas_equalTo(1);
        make.right.mas_equalTo(0);
    }];
    
    
    UILabel *yeasdayL = [[UILabel alloc] init];
    yeasdayL.font = FontBold(13);
    yeasdayL.textColor = [UIColor grayColor];
//    yeasdayL.text = @"使用本软件年龄需18岁以上";
    [self.view addSubview:yeasdayL];
    [yeasdayL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(birthLab.mas_bottom).offset(3);
        make.left.mas_equalTo(30*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(25*SCREEN_WIDTH_RATIO47);
        make.right.mas_equalTo(0);
    }];
    

    
    
    _nextButton = [[UIButton alloc] init];
    [_nextButton setTitle:@"下一步" forState:UIControlStateNormal];
    [_nextButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _nextButton.backgroundColor = Colorbackground;
    _nextButton.layer.cornerRadius = 12;
    _nextButton.layer.masksToBounds = YES;
    _nextButton.enabled = YES;
    
    [_nextButton addTarget:self action:@selector(clickNextButton) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_nextButton];
    [_nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(35);
        make.right.equalTo(self.view).offset (-35);
        make.top.equalTo(yeasdayL.mas_bottom).offset(130);
        make.height.mas_equalTo(50);
    }];
    


}

- (void)backActionbtn{
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(int)convertToInt:(NSString*)strtemp {
    
    int strlength = 0;
    char* p = (char*)[strtemp cStringUsingEncoding:NSUnicodeStringEncoding];
    for (int i=0 ; i<[strtemp lengthOfBytesUsingEncoding:NSUnicodeStringEncoding] ;i++) {
        if (*p) {
            p++;
            strlength++;
        }
        else {
            p++;
        }
    }
    return strlength;
    
}

- (void)nickNameTextFieldButton{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"请填写完整资料" message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *confirAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertVC addAction:confirAction];
    [self presentViewController:alertVC animated:YES completion:nil];
    


}
- (void)nickNameAlertView{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"昵称名不能为空!" message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *confirAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertVC addAction:confirAction];
    [self presentViewController:alertVC animated:YES completion:nil];

}
- (void)clickNextButton {
    [self.view endEditing:YES];
    self.dateView.hidden = YES;

    
    
    if (!_nickNameTextField.text.length||!_birthdayTextField.text.length||[_sex isEqualToNumber:@2]) {
        _nextButton.enabled = YES;
        
        [self nickNameTextFieldButton];
        return;
    }
    if (_nickNameTextField.text.length==0) {
        _nextButton.enabled = YES;
        [self nickNameAlertView];
        return;
    }
    

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"性别只能选择一次，不能修改，确定提交吗" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        _nextButton.enabled = YES;
    }];
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [SVProgressHUD show];
        NSString* identifierNumber = [[UIDevice currentDevice].identifierForVendor UUIDString] ;
        NSLog(@"手机序列号: %@",identifierNumber);
        [HQHttpManager updateUserWithUid:[HQHttpManager getUserId] mobile:nil photo:nil motto:nil sex:_sex nickName:_nickNameTextField.text birthday:_birthdayTextField.text animal:nil height:nil weight:nil affection:nil email:nil job:nil hometown:nil activeSite:nil skill:nil wantSkill:nil zfb:nil zfbName:nil  cardImg:nil video:nil privacy:nil isShield:nil successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
            _nextButton.enabled = YES;
            [SVProgressHUD dismiss];
            if (isSuccess) {
          
                NSString *modeStr = @"";
                
                if ([HQHttpManager getUserThirdNO].length>0) {
                    modeStr = @"third";
                }else{
                    modeStr = @"mobile";
                }
                
                [HQHttpManager userLoginWithAccout:[HQHttpManager userAccount] password:[HQHttpManager userPassword] thirdNO:[HQHttpManager getUserThirdNO] thirdType:[HQHttpManager getThirdType] mode:modeStr nickName:_nickNameTextField.text deviceNo:identifierNumber successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
                    [SVProgressHUD dismiss];
                    if (isSuccess) {
                        
                        RegisterPhotoViewController *RPVC = [[RegisterPhotoViewController alloc] init];
                        RPVC.sexNum = _sex.description;
                        
                        if ([_LoginType isEqualToString:@"1"]) {
                            [self.navigationController pushViewController:RPVC animated:YES];
                        }else{
                            self.view.window.rootViewController = RPVC;
                        }
                        
                    } else {
                        
                        _nextButton.enabled = YES;
                        
                    }
                    
                }];
            } else {
                _nextButton.enabled = YES;
            }
        }];
    }];
    [alert addAction:cancelAction];
    [alert addAction:sureAction];
    [self presentViewController:alert animated:YES completion:nil];
}
#pragma mark ===================    性别选择 ==============
- (void)clickSexButton:(UIButton *)sender {
    [self.view endEditing:YES];
    self.dateView.hidden = YES;
    if (sender == _manButton) {
        _manButton.selected = YES;
        _womanButton.selected = NO;
        [_manButton setTitleColor:ColorI(0xcc00b8f0) forState:UIControlStateSelected];
        _manImage.image = [UIImage imageNamed:@"boy_icon_pressed_w"];
        _womanImage.image = [UIImage imageNamed:@"girl_icon_default"];
        [_womanButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];

        _sex = @1;
    } else {
        _manButton.selected = NO;
        _womanButton.selected = YES;
        [_manButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        _manImage.image = [UIImage imageNamed:@"boy_icon_default_w"];
        _womanImage.image = [UIImage imageNamed:@"girl_icon_pressed"];
        [_womanButton setTitleColor:ColorI(0xccf0000b) forState:UIControlStateSelected];



        _sex = @0;
    }
    [self getAstroWithMonth:[_stringConMon intValue] day:[_stringConDay intValue]];
}

- (void)clickBirthdayButton {
    [self.view endEditing:YES];
    self.dateView.hidden = NO;
}

- (UIDatePicker *)datePicker {
    if (!_datePicker) {
        _datePicker = [[UIDatePicker alloc]init];
        _datePicker.backgroundColor = [UIColor whiteColor];
        _datePicker.frame = CGRectMake(0, 40, KScreenWidth, 200);
        NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
        _datePicker.locale = locale;
        _datePicker.datePickerMode = UIDatePickerModeDate;
        NSDate *maxDate = [[NSDate alloc]initWithTimeIntervalSinceNow:24*60*60];
        _datePicker.maximumDate = maxDate;
        NSDate *minDate = [NSDate date];
        _datePicker.maximumDate = minDate;
    }
    return _datePicker;
}

- (UIView *)dateView {
    if (!_dateView) {
        _dateView = [[UIView alloc] init];
        _dateView.backgroundColor = [UIColor whiteColor];
        _dateView.frame = CGRectMake(0, KScreenHeight-240, KScreenWidth, 240);
        [_dateView addSubview:self.datePicker];
        
        UILabel *Tlab = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, _dateView.width, 20)];
        Tlab.backgroundColor = [UIColor whiteColor];
        Tlab.font = FontP(9);
        Tlab.textAlignment = NSTextAlignmentCenter;
        Tlab.text = @"选择出生日期，系统将自动转为星座";
        [_dateView addSubview:Tlab];
        
        UIButton *confirmButton = [[UIButton alloc] initWithFrame:CGRectMake(KScreenWidth - 60, 10, 60, 20)];
        [confirmButton setTitleColor:Colorbackground forState:UIControlStateNormal];
        
        [confirmButton setTitle:@"确定" forState:UIControlStateNormal];
        
        [confirmButton addTarget:self action:@selector(dateViewConfirm) forControlEvents:UIControlEventTouchUpInside];
        
        [_dateView addSubview:confirmButton];

        
        
        UIButton *cancelButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 10, 60, 20)];
        [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
        [cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_dateView addSubview:cancelButton];
        [cancelButton addTarget:self action:@selector(dateViewDismiss) forControlEvents:UIControlEventTouchUpInside];
        UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 1)];
        line.backgroundColor = RGB(242, 244, 244);
        [_dateView addSubview:line];
        [self.view addSubview:_dateView];
    }
    return _dateView;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [self.view endEditing:YES];
    self.dateView.hidden = YES;
    
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    
    self.dateView.hidden = YES;
    return YES;
}

- (void)dateViewConfirm {
    
    self.dateView.hidden = YES;
    NSDateFormatter *fmt = [[NSDateFormatter alloc]init];
    fmt.dateFormat = @"yyyy-MM-dd";
    NSString *dateStr = [fmt stringFromDate:_datePicker.date];
    //判断是否大于等于18岁
    NSDate *currentDate = [NSDate date];
    
    //星座判断时间截取
    
    
    _stringConMon = [dateStr substringWithRange:NSMakeRange(5,2)];
    _stringConDay = [dateStr substringWithRange:NSMakeRange(8, 2)];
    NSLog(@"截取的值为：%@  ==%@",_stringConMon,_stringConDay);
    
    
    NSCalendar *calendar = [NSCalendar currentCalendar];
    unsigned int unitFlags = NSCalendarUnitYear;
    NSDateComponents *date = [calendar components:unitFlags fromDate:_datePicker.date toDate:currentDate options:0];
    
    if((long)[date year]>=18){
        _birthdayTextField.text = dateStr;
        [self getAstroWithMonth:[_stringConMon intValue] day:[_stringConDay intValue]];

    }
    else{
        _birthdayTextField.text = @"";
        [self dateDayMonAlerter];
    }
}

- (void)birthdayTextFieldButton{
   
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"昵称名不能为空!" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    [alert show];
}

- (void)dateViewDismiss {
    self.dateView.hidden = YES;
}

- (void)dateDayMonAlerter{
    
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"使用本软件年龄不得低于18岁" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    [alert show];
}



-(NSString *)getAstroWithMonth:(int)m day:(int)d{
    
    NSString *astroString = @"摩羯水瓶双鱼白羊金牛双子巨蟹狮子处女天秤天蝎射手摩羯";
    NSString *astroFormat = @"102123444543";
    NSString *result;
    
    if (m<1||m>12||d<1||d>31){
        return @"错误日期格式!";
    }
    
    if(m==2 && d>29)
    {
        return @"错误日期格式!!";
    }else if(m==4 || m==6 || m==9 || m==11) {
        
        if (d>30) {
            return @"错误日期格式!!!";
        }
    }
    
    result=[NSString stringWithFormat:@"%@",[astroString substringWithRange:NSMakeRange(m*2-(d < [[astroFormat substringWithRange:NSMakeRange((m-1), 1)] intValue] - (-19))*2,2)]];
    
    _constellationStr = result;
    
    
    
    if ([result isEqualToString:@"摩羯"]) {
        if ([_sex isEqualToNumber:@0]) {
            _constellationImg.image = [UIImage imageNamed:@"capricornius_icon"];
        }else{
            _constellationImg.image = [UIImage imageNamed:@"capricornius_icon_w"];

        }
    }else if ([result isEqualToString:@"水瓶"]){
        if ([_sex isEqualToNumber:@0]) {
            _constellationImg.image = [UIImage imageNamed:@"aquarius_icon"];
        }else{
            _constellationImg.image = [UIImage imageNamed:@"aquarius_icon_w"];
            
        }
    }else if ([result isEqualToString:@"双鱼"]){
        if ([_sex isEqualToNumber:@0]) {
            _constellationImg.image = [UIImage imageNamed:@"pisces_icon"];
        }else{
            _constellationImg.image = [UIImage imageNamed:@"pisces_icon_w"];
            
        }
    }else if ([result isEqualToString:@"白羊"]){
        if ([_sex isEqualToNumber:@0]) {
            _constellationImg.image = [UIImage imageNamed:@"aries_icon"];
        }else{
            _constellationImg.image = [UIImage imageNamed:@"aries_icon_w"];
            
        }
    }else if ([result isEqualToString:@"金牛"]){
        if ([_sex isEqualToNumber:@0]) {
            _constellationImg.image = [UIImage imageNamed:@"taurus_icon"];
        }else{
            _constellationImg.image = [UIImage imageNamed:@"taurus_icon_w"];
            
        }
    }else if ([result isEqualToString:@"双子"]){
        if ([_sex isEqualToNumber:@0]) {
            _constellationImg.image = [UIImage imageNamed:@"gemini_icon"];
        }else{
            _constellationImg.image = [UIImage imageNamed:@"gemini_icon_w"];
            
        }
    }else if ([result isEqualToString:@"巨蟹"]){
        if ([_sex isEqualToNumber:@0]) {
            _constellationImg.image = [UIImage imageNamed:@"cancer_icon"];
        }else{
            _constellationImg.image = [UIImage imageNamed:@"cancer_icon_w"];
            
        }
    }else if ([result isEqualToString:@"狮子"]){
        if ([_sex isEqualToNumber:@0]) {
            _constellationImg.image = [UIImage imageNamed:@"leo_icon"];
        }else{
            _constellationImg.image = [UIImage imageNamed:@"leo_icon_w"];
            
        }
    }else if ([result isEqualToString:@"处女"]){
        if ([_sex isEqualToNumber:@0]) {
            _constellationImg.image = [UIImage imageNamed:@"virgo_icon"];
        }else{
            _constellationImg.image = [UIImage imageNamed:@"virgo_icon_w"];
            
        }
    }else if ([result isEqualToString:@"天秤"]){
        if ([_sex isEqualToNumber:@0]) {
            _constellationImg.image = [UIImage imageNamed:@"libra_icon"];
        }else{
            _constellationImg.image = [UIImage imageNamed:@"libra_icon_w"];
            
        }
    }else if ([result isEqualToString:@"天蝎"]){
        if ([_sex isEqualToNumber:@0]) {
            _constellationImg.image = [UIImage imageNamed:@"scorpius_icon"];
        }else{
            _constellationImg.image = [UIImage imageNamed:@"scorpius_icon_w"];
            
        }
    }else if([result isEqualToString:@"射手"]){
        if ([_sex isEqualToNumber:@0]) {
            _constellationImg.image = [UIImage imageNamed:@"sagittarius_symbol_icon"];
        }else{
            _constellationImg.image = [UIImage imageNamed:@"sagittarius_symbol_icon_w"];
            
        }
    }
    _constellationImg.hidden = NO;
    
    return _constellationLab.text = [NSString stringWithFormat:@"%@座",result];

    
}
- (void)limitTextLimitInput:(HSLimitText *)textLimitInput text:(NSString *)text
{
    if([textLimitInput isEqual:self.nickNameTextField]){
        self.nickNameTextField.text = text;
    }
    else{
        
    }
    
}


- (void)limitTextLimitInputOverStop:(HSLimitText *)textLimitInput
{
    NSLog(@"%@",@"超出什么都不做 直接截断");
}



@end
